package com.it2297.model;

import java.util.ArrayList;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
public class GenericTableModel<T> extends AbstractTableModel
{
	private String[] columns;
	private ArrayList<T> objects;

	public GenericTableModel(String[] columns, ArrayList<T> objects)
	{
		this.columns = columns;
		this.objects = objects;
	}

	@Override
	public int getColumnCount()
	{
		return columns.length;
	}

	@Override
	public int getRowCount()
	{
		return objects.size();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex)
	{
		return objects.get(rowIndex);
	}

	@Override
	public String getColumnName(int column)
	{
		return columns[column];
	}
	
	public void setValues(ArrayList<T> objects){
		this.objects = objects;
		fireTableDataChanged();
	}
}
